home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / str2bmp / test.frm < prev    next >
Text File  |  1995-09-06  |  9KB  |  324 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00FF0000&
  4.    Caption         =   "Bitmap Function Tester."
  5.    ClientHeight    =   4050
  6.    ClientLeft      =   1860
  7.    ClientTop       =   2190
  8.    ClientWidth     =   7245
  9.    ClipControls    =   0   'False
  10.    Height          =   4455
  11.    Left            =   1800
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   4050
  14.    ScaleWidth      =   7245
  15.    Top             =   1845
  16.    Width           =   7365
  17.    Begin CommandButton CommandCopyResultToB 
  18.       Caption         =   "Copy RESULT to B"
  19.       Height          =   555
  20.       Left            =   5040
  21.       TabIndex        =   12
  22.       Top             =   1380
  23.       Width           =   2055
  24.    End
  25.    Begin CommandButton CommandAnd 
  26.       Caption         =   "RESULT = A AND B"
  27.       Height          =   555
  28.       Left            =   5040
  29.       TabIndex        =   11
  30.       Top             =   780
  31.       Width           =   2055
  32.    End
  33.    Begin PictureBox PictureResult 
  34.       AutoRedraw      =   -1  'True
  35.       BorderStyle     =   0  'None
  36.       Height          =   615
  37.       Left            =   3240
  38.       ScaleHeight     =   41
  39.       ScaleMode       =   3  'Pixel
  40.       ScaleWidth      =   81
  41.       TabIndex        =   7
  42.       Top             =   2820
  43.       Width           =   1215
  44.    End
  45.    Begin CommandButton CommandOr 
  46.       Caption         =   "RESULT = A OR B"
  47.       Height          =   555
  48.       Left            =   5040
  49.       TabIndex        =   6
  50.       Top             =   180
  51.       Width           =   2055
  52.    End
  53.    Begin CommandButton CommandInvertA 
  54.       Caption         =   "Invert A"
  55.       Height          =   555
  56.       Left            =   5040
  57.       TabIndex        =   5
  58.       Top             =   3180
  59.       Width           =   2055
  60.    End
  61.    Begin CommandButton CommandCompareAtoB 
  62.       Caption         =   "Compare A to B"
  63.       Height          =   555
  64.       Left            =   5040
  65.       TabIndex        =   4
  66.       Top             =   2580
  67.       Width           =   2055
  68.    End
  69.    Begin PictureBox PictureA 
  70.       AutoRedraw      =   -1  'True
  71.       BorderStyle     =   0  'None
  72.       Height          =   615
  73.       Left            =   360
  74.       ScaleHeight     =   41
  75.       ScaleMode       =   3  'Pixel
  76.       ScaleWidth      =   81
  77.       TabIndex        =   3
  78.       Top             =   2820
  79.       Width           =   1215
  80.    End
  81.    Begin PictureBox PictureB 
  82.       AutoRedraw      =   -1  'True
  83.       BorderStyle     =   0  'None
  84.       Height          =   615
  85.       Left            =   1800
  86.       ScaleHeight     =   41
  87.       ScaleMode       =   3  'Pixel
  88.       ScaleWidth      =   81
  89.       TabIndex        =   2
  90.       Top             =   2820
  91.       Width           =   1215
  92.    End
  93.    Begin CommandButton CommandCopyAtoB 
  94.       Caption         =   "Copy A to B"
  95.       Height          =   555
  96.       Left            =   5040
  97.       TabIndex        =   1
  98.       Top             =   1980
  99.       Width           =   2055
  100.    End
  101.    Begin CommandButton CommandDrawCircle 
  102.       Caption         =   "Draw Circles in A"
  103.       Height          =   555
  104.       Left            =   600
  105.       TabIndex        =   0
  106.       Tag             =   "Write line to A"
  107.       Top             =   600
  108.       Width           =   3495
  109.    End
  110.    Begin Label Label3 
  111.       BackColor       =   &H00FF0000&
  112.       Caption         =   "A"
  113.       FontBold        =   -1  'True
  114.       FontItalic      =   0   'False
  115.       FontName        =   "MS Sans Serif"
  116.       FontSize        =   12
  117.       FontStrikethru  =   0   'False
  118.       FontUnderline   =   0   'False
  119.       ForeColor       =   &H00FFFFFF&
  120.       Height          =   255
  121.       Left            =   840
  122.       TabIndex        =   10
  123.       Top             =   3540
  124.       Width           =   255
  125.    End
  126.    Begin Label Label2 
  127.       BackColor       =   &H00FF0000&
  128.       Caption         =   "B"
  129.       FontBold        =   -1  'True
  130.       FontItalic      =   0   'False
  131.       FontName        =   "MS Sans Serif"
  132.       FontSize        =   12
  133.       FontStrikethru  =   0   'False
  134.       FontUnderline   =   0   'False
  135.       ForeColor       =   &H00FFFFFF&
  136.       Height          =   255
  137.       Left            =   2280
  138.       TabIndex        =   9
  139.       Top             =   3600
  140.       Width           =   255
  141.    End
  142.    Begin Label Label1 
  143.       BackColor       =   &H00FF0000&
  144.       Caption         =   "Result"
  145.       FontBold        =   -1  'True
  146.       FontItalic      =   0   'False
  147.       FontName        =   "MS Sans Serif"
  148.       FontSize        =   12
  149.       FontStrikethru  =   0   'False
  150.       FontUnderline   =   0   'False
  151.       ForeColor       =   &H00FFFFFF&
  152.       Height          =   255
  153.       Left            =   3480
  154.       TabIndex        =   8
  155.       Top             =   3540
  156.       Width           =   855
  157.    End
  158. End
  159. Option Explicit
  160.  
  161. ' Strings to hold pixel information.
  162. Dim A$
  163. Dim B$
  164. Dim RESULT$
  165.  
  166. Sub CommandAnd_Click ()
  167.   Dim bytes As Long
  168.   Dim ret%
  169.  
  170.   bytes = BMP_GetSize(PictureA.Image)
  171.   If (bytes = 0) Then
  172.      MsgBox ("Bitmap too large to store!")
  173.      End
  174.   End If
  175.   A$ = Space$(bytes)
  176.   B$ = Space$(bytes)
  177.   RESULT$ = Space$(bytes)
  178.   ret% = BMPToString(PictureA.hDC, PictureA.Image, A$)
  179.   ret% = BMPToString(PictureB.hDC, PictureB.Image, B$)
  180.  
  181.   bytes = StringBMP_and(A$, B$, RESULT$)
  182.  
  183.   ret% = StringToBmp(RESULT$, PictureResult.hDC, PictureResult.Image)
  184.   PictureResult.Refresh
  185.  
  186. End Sub
  187.  
  188. Sub CommandCompareAtoB_Click ()
  189.   Dim bytes As Long
  190.   Dim A$, B$
  191.   Dim ret%
  192.  
  193.   bytes = BMP_GetSize(PictureA.Image)
  194.   If (bytes = 0) Then
  195.      MsgBox ("Bitmap too large to store!")
  196.      End
  197.   End If
  198.   A$ = Space$(bytes)
  199.   B$ = Space$(bytes)
  200.   ret% = BMPToString(PictureA.hDC, PictureA.Image, A$)
  201.  
  202.   If BMP_GetSize(PictureB.Image) <> bytes Then
  203.      MsgBox "Bitmaps must be same size to compare. "
  204.      End
  205.   End If
  206.   ret% = BMPToString(PictureB.hDC, PictureB.Image, B$)
  207.  
  208.   bytes = StringBMP_Compare(A$, B$)
  209.  
  210.   MsgBox "This difference is " + Str$(bytes) + " pixels."
  211.  
  212. End Sub
  213.  
  214. Sub CommandCopyAtoB_Click ()
  215.   Dim ret%
  216.   B$ = A$
  217.   ' Fill PictureBox with information in B$
  218.   ret% = StringToBmp(B$, PictureB.hDC, PictureB.Image)
  219.   ' Display the new information
  220.    PictureB.Refresh
  221. End Sub
  222.  
  223. Sub CommandCopyResultToB_Click ()
  224.   Dim ret%
  225.  
  226.   ' Copy RESULT to B (STRINGS!)
  227.   B$ = RESULT$
  228.  
  229.   ' Convert the new B$ to a picture and display it!
  230.   ret% = StringToBmp(B$, PictureB.hDC, PictureB.Image)
  231.   PictureB.Refresh
  232.  
  233. End Sub
  234.  
  235. Sub CommandDrawCircle_Click ()
  236.   Dim ret%
  237.   Dim bytes As Long
  238.   
  239.   ' Draw a black circle
  240.   PictureA.FillStyle = 0
  241.   
  242.   PictureA.FillColor = RGB(0, 0, 0)
  243.   PictureA.Circle (10, 10), 5, RGB(0, 0, 0)
  244.   
  245.   PictureA.FillColor = RGB(255, 0, 0)
  246.   PictureA.Circle (40, 25), 5, RGB(255, 0, 0)
  247.   
  248.   PictureA.FillColor = RGB(0, 255, 0)
  249.   PictureA.Circle (25, 30), 5, RGB(0, 255, 0)
  250.   
  251.   ' Determine the size of a string required to hold PictureA
  252.   bytes = BMP_GetSize(PictureA.Image)
  253.   If (bytes = 0) Then
  254.      MsgBox ("Bitmap too large to store as a string!")
  255.      End
  256.   End If
  257.   
  258.   ' Create a string of the proper size to hold picture box.
  259.   A$ = Space$(bytes)
  260.  
  261.   ' Convert PictureA into A$
  262.   ret% = BMPToString(PictureA.hDC, PictureA.Image, A$)
  263.  
  264. End Sub
  265.  
  266. Sub CommandInvertA_Click ()
  267.   Dim bytes As Long
  268.   Dim ret%
  269.   Dim TEMP$
  270.  
  271.   ' Determine the size of a string required to hold PictureA
  272.   bytes = BMP_GetSize(PictureA.Image)
  273.   If (bytes = 0) Then
  274.      MsgBox ("Bitmap too large to store!")
  275.      End
  276.   End If
  277.  
  278.   ' Make sure space is allocated to hold all pixels in strings.
  279.   A$ = Space$(bytes)
  280.   TEMP$ = Space$(bytes)
  281.                               
  282.   ' Copy PictureA into A$
  283.   ret% = BMPToString(PictureA.hDC, PictureA.Image, A$)
  284.  
  285.   ' Invert A$ and store the result in RESULT$
  286.   ret% = StringBMP_Invert(A$, TEMP$)
  287.   A$ = TEMP$
  288.  
  289.   ' Convert A$ into a picture box and display.
  290.   ret% = StringToBmp(A$, PictureA.hDC, PictureA.Image)
  291.   PictureA.Refresh
  292.  
  293. End Sub
  294.  
  295. Sub CommandOr_Click ()
  296.   Dim bytes As Long
  297.   Dim ret%
  298.  
  299.   ' Make sure string